﻿/**********************************************************
 ●项目：Smartkernel
 ●公司：智能核心信息技术研发中心
 ●作者：曹艳白
 ●邮箱：caoyanbai@gmail.com
 ●创建：2008-08-10
**********************************************************/
using System;
using System.Globalization;

namespace Smartkernel
{
    /// <summary>
    /// 时间操作的相关功能
    /// </summary>
    public static class SmartDateTime
    {
        /// <summary>
        /// 计算两个日期之间相差的间隔
        /// </summary>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="smartDateTimeType">间隔类型</param>
        /// <returns>相差的天数</returns>
        public static double Distance(DateTime start, DateTime end, SmartDateTimeType smartDateTimeType)
        {
            TimeSpan timeSpan = end.Subtract(start);
            double distance = 0;
            switch (smartDateTimeType)
            {
                case SmartDateTimeType.Hour:
                    distance = timeSpan.TotalHours;
                    break;
                case SmartDateTimeType.Millisecond:
                    distance = timeSpan.TotalMilliseconds;
                    break;
                case SmartDateTimeType.Minute:
                    distance = timeSpan.TotalMinutes;
                    break;
                case SmartDateTimeType.Month:
                    distance = timeSpan.TotalDays / 30;
                    break;
                case SmartDateTimeType.Second:
                    distance = timeSpan.TotalSeconds;
                    break;
                case SmartDateTimeType.Year:
                    distance = timeSpan.TotalDays / 365;
                    break;
                case SmartDateTimeType.Day:
                    distance = timeSpan.TotalDays;
                    break;
            }
            return distance;
        }
        /// <summary>
        /// 获得某一年的天数
        /// </summary>
        /// <param name="year">年份</param>
        /// <returns>天数</returns>
        public static int GetDaysInYear(int year)
        {
            GregorianCalendar gregorianCalendar = new GregorianCalendar();
            return gregorianCalendar.GetDaysInYear(year);
        }
        /// <summary>
        /// 获得某一年的某个月的天数
        /// </summary>
        /// <param name="year">年份</param>
        /// <param name="month">月份</param>
        /// <returns>天数</returns>
        public static int GetDaysInMonth(int year, int month)
        {
            GregorianCalendar gregorianCalendar = new GregorianCalendar();
            return gregorianCalendar.GetDaysInMonth(year, month);
        }
        /// <summary>
        /// 根据年份判断生肖
        /// </summary>
        /// <param name="year">年份</param>
        /// <returns>生肖</returns>
        public static SmartTwelveAnimalType GetSmartTwelveAnimal(int year)
        {
            SmartTwelveAnimalType animal = SmartTwelveAnimalType.鼠;
            switch (year % 12)
            {
                case 4:
                    animal = SmartTwelveAnimalType.鼠;
                    break;
                case 5:
                    animal = SmartTwelveAnimalType.牛;
                    break;
                case 6:
                    animal = SmartTwelveAnimalType.虎;
                    break;
                case 7:
                    animal = SmartTwelveAnimalType.兔;
                    break;
                case 8:
                    animal = SmartTwelveAnimalType.龙;
                    break;
                case 9:
                    animal = SmartTwelveAnimalType.蛇;
                    break;
                case 10:
                    animal = SmartTwelveAnimalType.马;
                    break;
                case 11:
                    animal = SmartTwelveAnimalType.羊;
                    break;
                case 0:
                    animal = SmartTwelveAnimalType.猴;
                    break;
                case 1:
                    animal = SmartTwelveAnimalType.鸡;
                    break;
                case 2:
                    animal = SmartTwelveAnimalType.狗;
                    break;
                case 3:
                    animal = SmartTwelveAnimalType.猪;
                    break;
            }
            return animal;
        }
    }
}
